package org.accp.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.accp.dao.ZhiliaoyiDao;
import org.accp.pojo.Register;
import org.accp.pojo.Zhiliaoyi;
import org.accp.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/zhiliaoyi")
@CrossOrigin("*")
public class ZhiliaoyiController {
    @Autowired
    private ZhiliaoyiDao zhiliaoyiDao;

    public void setZhiliaoyiDao(ZhiliaoyiDao zhiliaoyiDao) {
        this.zhiliaoyiDao = zhiliaoyiDao;
    }
    @RequestMapping("/list")
    @ResponseBody
    public ResponseResult<List<Zhiliaoyi>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, Zhiliaoyi zhiliaoyi) throws Exception {
        Page<Zhiliaoyi> pager = PageHelper.startPage(page, limit);
        List<Zhiliaoyi> list = zhiliaoyiDao.getConditionList(zhiliaoyi);
        return new ResponseResult(pager.getTotal(), list);
    }

    @RequestMapping("/add")
    @ResponseBody
    public ResponseResult add(Zhiliaoyi zhiliaoyi) throws Exception{
        zhiliaoyiDao.add(zhiliaoyi);
        return ResponseResult.createSuccessResult();
    }
}






























